package com.imoney.payment.member.generator;

import java.util.List;

import org.springframework.stereotype.Service;

import com.imoney.framework.base.entity.IRequest;
import com.imoney.payment.common.ValidateUtil;
import com.imoney.payment.generator.AbstractGenerator;
import com.imoney.payment.member.domain.Member;
import com.imoney.payment.member.domain.RegCompleteRequest;
import com.imoney.payment.member.domain.RegRequest;
import com.imoney.payment.member.enums.AccStatus;
import com.imoney.payment.member.enums.LoginType;

/**
 * 类说明：<br>
 * 
 * <p>
 * 详细描述：<br>
 * 
 * </p>
 * 
 * <pre>
 * ——————————————————————————————————————————————————————————————————
 * |		修改人		|		修改时间			|		修改原因
 * ——————————————————————————————————————————————————————————————————
 * |	zengxx 曾宪新	|		2013-6-16		|	
 * ——————————————————————————————————————————————————————————————————
 * </pre>
 * 
 * @author zengxx 曾宪新(Xavier.zeng)
 * 
 *         CreateDate: 2013-6-16
 */
@Service
public class MemberGenerator extends AbstractGenerator<Member> {

	@Override
	public Member generate(IRequest request) {

		Member member = new Member();
		if (request instanceof RegRequest) {
			RegRequest regRequest = (RegRequest) request;
			
			member.setUserName(regRequest.getLoginId());
			member.setUserType(regRequest.getUserType());
			if (ValidateUtil.isMobile(regRequest.getLoginId())) {
				member.setLoginType(LoginType.MOBILE);
			} else {
				member.setLoginType(LoginType.EMAIL);
			}
			member.setCountry(regRequest.getCountry());
			member.setStatus(AccStatus.activate);
		}
		else if (request instanceof RegCompleteRequest) {
			RegCompleteRequest regRequest = (RegCompleteRequest) request;
			
			member.setUserName(regRequest.getLoginId());
			member.setPassword(regRequest.getQueryPwd());
			member.setNickname(regRequest.getRealName());
		}
		
		return member;
	}

	@Override
	public List<Member> generateList(IRequest request) {

		return null;
	}

}
